#!C:/strawberry/perl/bin/perl.exe

use strict;
use warnings;

use CGI qw(:standard);
use RPC::XML;
use RPC::XML::Client;
use Data::Dumper;
use XML::Simple;
use XML::eXistDB::RPC;
use XML::Compile::RPC::Client;



# read the CGI params
my $cgi = CGI->new;
my $email = $cgi->param("email");
#my $email='juanjo@lopez.com';


my $eXist = XML::eXistDB::RPC->new( destination=>"http://localhost:8080/exist/xmlrpc", repository=>"/db", user=>"admin", password=>"eaf2julian" ) ;



my $xquery = <<END;
    for \$puntero in doc("/placeanddate/usuarios.xml")/usuarios/usuario[email/text() eq "$email"]
    return
        update delete \$puntero
END

my ($rc1, $set) = $eXist->executeQuery($xquery) ;

# create a JSON string according to the database result
my $json =qq{{"success" : "$rc1"}};

# return JSON string
print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json;